let obj = {
  a: [1, 2, 3, 4],
  b: 2,
  c: {
    c1: 1,
    c2: 3
  }
};

function def(obj, key, value) {
  if (typeof value == "object" && value != null) {
    if (Array.isArray(obj)) return;

    for (let key1 in value) {
      def(value, key1, value[key1])
    }
  }
  Object.defineProperty(obj, key, {
    get() {
      console.log("获取key————" + key);
      return value;
    },
    set(newVal) {
      if (newVal == value) return;
      value = newVal;
    }
  })
}
for (let key in obj) {
  let val = obj[key];
  def(obj, key, val);
}

console.log(JSON.stringify(obj));

// for (let key in obj) {
//   let val = obj[key]
//   Object.defineProperty(obj, key, {
//     get() {
//       console.log("获取key————" + key);
//       return val;
//     },
//     set(newVal) {
//       if (newVal == val) return;
//       obj[key] = newVal;
//     }
//   })
//   //   console.log(key);
// }